package com.lukebang.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.lukebang.constant.Const;
import com.lukebang.pojo.Merchant;

/**
 * 
 * LoginHandlerInterceptor 下午5:57:30 Copyright zhaocj Inc. All Rights reserved.
 * alldios@outlook.com
 *
 */
public class LoginHandlerInterceptor extends HandlerInterceptorAdapter {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		HttpSession session = request.getSession();
		Merchant merchant = (Merchant) session.getAttribute(Const.SESSION_USER);
		if (merchant != null) {
			return true;
		} else {
			response.sendRedirect(request.getContextPath() + "/login.html");
			return false;
		}
	}
}
